package com.WEG_ee890.TempMON;



import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TempMONActivity extends Activity {
    
	private static final int REQUEST_ENABLE_BT = 0;
	public Button view_log;
	
	
	 protected void onActivityResult(int requestCode, int resultCode, Intent bluetoothEnable) {
     	if (requestCode == REQUEST_ENABLE_BT) {
     		if (resultCode == RESULT_CANCELED) {
     			AlertDialog.Builder BtAlert = new AlertDialog.Builder(this);
     			BtAlert.setMessage("This application will not work without enabling Bluetooth!")
     			       .setCancelable(true)
     			       .setNeutralButton("Ok", new DialogInterface.OnClickListener() {				
     			    	   public void onClick(DialogInterface dialog1, int id) {					
     			    		   dialog1.cancel();
    	           }
     	       });
     		AlertDialog BtAlertDialog = BtAlert.create();
     		BtAlertDialog.show();
     		}
     	}
     }
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        
        if (mBluetoothAdapter == null) {
            // Device does not support Bluetooth, show dialog box saying so
        	AlertDialog.Builder builder = new AlertDialog.Builder(this);
        	builder.setMessage("Your device doesn't support Bluetooth connectivity")
        	       .setCancelable(false)
        	       .setNeutralButton("Ok", new DialogInterface.OnClickListener() {
        	           public void onClick(DialogInterface dialog, int id) {
        	                dialog.cancel();
        	           }
        	       });
        	       
        	AlertDialog alert = builder.create();
            alert.show();
        }
        
        if (!mBluetoothAdapter.isEnabled()) {												// this line is hanging the emulator
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        }
        
       
        
        final Button temperature_read = (Button) findViewById(R.id.button1);
        temperature_read.setOnClickListener(new View.OnClickListener() {
            public void onClick(View button_1) {
            	// kick off Bluetooth read from Explorer 16 board
            	
            }
        });
        
        view_log = (Button) findViewById(R.id.button2);
        view_log.setOnClickListener(mylistener);
        	
    }
    private OnClickListener mylistener = new OnClickListener() {
        public void onClick(View button_2) {

	Intent logScreen = new Intent(getApplicationContext(), TemperatureLogFile.class);
	startActivity(logScreen);	
        }
    };
   
    @Override
    public void onStart() {
        super.onStart();
        
    }

    @Override
    public synchronized void onResume() {
        super.onResume();
        
    }
    
    @Override
    public synchronized void onPause() {
        super.onPause();
        
    }

    @Override
    public void onStop() {
        super.onStop();
        
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        
    }


}